<?php
/**
 * Created by PhpStorm.
 * User: 爱尔
 * Date: 2020/9/23
 * Time: 13:38
 */

namespace app\admin\controller;
use app\admin\model\GroupmindModel;
use app\admin\model\CombonameModel;
use PhpOffice\PhpWord\Settings;
use think\Controller;
use think\Db;

class CreateContract extends Controller{
    //获取菜单的列表
    public function getMenu(){
        $id = input('param.id');
        $para['isdelete']=0;
        $result = Db::name('sys_menu')->where($para)->order('ordernum asc')->select();

        $menu = [];
        $child = [];

        $str='abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
        $len=strlen($str)-1;

        foreach($result as $key=>$vo){
            $temp = array();
            if(0 == $vo['parentid']){
                $temp['edit_node_user'] = 'admin';
                $temp['edit_time'] = date('Y-m-d');
                $temp['id'] = GetRandStr(10);
                $temp['temp_id'] = $vo['id'];
                $temp['parentid'] = 'sub1';//设定父级节点是功能模块
                $temp['price'] = '0.00';
                $temp['topic'] = $vo['title'].'/'.$temp['price'];
                $temp['only_topic'] = $vo['title'];
                $menu[] = $temp;
            }else{
                $child[] = $vo;
            }
        }

        if(isset($id)){
            $groupmindModel = GroupmindModel::get($id);
            $mind_data = $groupmindModel->mind_json;
            $mind_data = json_decode($mind_data,true);
            foreach ($mind_data as $key => $value){
                foreach ($menu as $key1 => $value1){
                    if($value["topic"] == $value1["topic"] || $value["only_topic"] == $value1["only_topic"] || $value["only_topic"] == $value1["only_topic"]){
                        unset($menu[$key1]);
                    }
                }
            }
        }

        foreach($menu as $key=>$vo){
            foreach($child as $k=>$v){
                $temp = array();
                if($v['parentid'] == $vo['temp_id']){
                    $temp['edit_node_user'] = 'admin';
                    $temp['edit_time'] = date('Y-m-d');
                    $temp['id'] = GetRandStr(10);
                    $temp['parentid'] = $vo['id'];//设定父级节点是功能模块
                    $temp['price'] = '0.00';
                    $temp['topic'] = $v['title'].'/'.$temp['price'];
                    $temp['only_topic'] =$v['title'];
                    $menu[] = $temp;
                }
            }
        }

        if($menu){
            $ret['data'] = $menu;
            $ret['code'] = 0;
            $ret['msg']  = '获取数据成功';
        }else{
            $ret['data'] = '';
            $ret['code'] = -1;
            $ret['msg']  = '获取数据为空';
        }

        return $ret;
    }

    public function create_mind(){
        $manage = input('param.manage');
        $id = input('param.id');
        $manage = isset($manage)?$manage : 0;
        $groupmindModel = new GroupmindModel();
        if(isset($id) && !empty($id)){
            $this->assign('id',$id);
            $mind_data_array = $groupmindModel->getMindData($id,$manage);
            //dump($mind_data_array['data']);exit;
            $save_type = 'eidt';
            $mind_data = json_encode($mind_data_array['data']);
        }else{
            $this->assign('id',0);
            $save_type = 'add';
            //$mind_data = $groupmindModel->createDefaltNote();
            //$mind_data = json_encode($mind_data);
            $mind_data = '[]';
        }
        //dump($mind_data);exit;
        //dump(json_encode($mind_data['data']));exit;
        //dump($mind_data);exit;
        //$this->assign('is_edit_mind',$mind_data_array['header']['is_edit_mind']);
        $this->assign('is_edit_mind',1);
        $this->assign('manage',$manage);
        $this->assign('save_type',$save_type);
        $this->assign('mind_data',$mind_data);
        return $this->fetch('create');
    }

    public function simple_mind(){
        $manage = input('param.manage');
        $id = input('param.id');
        $timetype = input('param.timetype');
        $meed_back = false;
        if(isset($timetype) && $timetype != 0){
            $oneday = 24 * 60 * 60 * $timetype;
            $meed_back = true;
        }
        $manage = isset($manage)?$manage : 0;
        $groupmindModel = new GroupmindModel();
        if(isset($id) && !empty($id)){
            $this->assign('id',$id);
            $save_type = 'edit';
            $groupmindModel = GroupmindModel::get($id);
            $mind_data = $groupmindModel->mind_json;
            $mind_data = json_decode($mind_data,true);

            foreach ($mind_data as $key => $value){
                if(isset($value['background-color'])){
                    unset($mind_data[$key]['background-color']);
                }
                if($meed_back === true && isset($value['edit_time'])){
                    $edite_time = strtotime($value['edit_time']);
                    if(($edite_time + $oneday) > time()){
                        $mind_data[$key]['background-color'] = 'red';
                    }
                }
                $is_h = strpos($value['topic'],"/");
                if($is_h > 0){
                    $mind_data[$key]['topic'] = substr($value['topic'],0,$is_h);
                }else{
                    $mind_data[$key]['topic'] = $value['topic'];
                }
            }
            //dump($mind_data);exit;
            $mind_data = json_encode($mind_data);

        }else{
            $this->assign('id',0);
            $save_type = 'add';
            $mind_data = '[]';
        }
        if($groupmindModel->is_edit_mind == null){
            $this->assign('is_edit_mind',0);
        }else{
            $this->assign('is_edit_mind',$groupmindModel->is_edit_mind);
        }

        $this->assign('manage',$manage);
        $this->assign('save_type',$save_type);
        $this->assign('mind_data',$mind_data);
        return $this->fetch();
    }

    public function saveSimpleMind(){
        $param = input('param.');
        $groupmindModel = GroupmindModel::get($param['id']);

        $data_array = json_decode($param['data'],true);

        foreach ($data_array as $key => $value){
            if(isset($value['background-color'])){
                unset($data_array[$key]['background-color']);
            }
            $is_h = strpos($value['topic'],"/");
            if($is_h){
                $data_array[$key]['only_topic'] = substr($value['topic'],0,$is_h);
                $data_array[$key]['topic'] = substr($value['topic'],0,$is_h);
            }

            if(isset($value['add_node_user_select']) && $value['add_node_user_select'] == 'true'){
                $data_array[$key]['add_time'] = date('Y-m-d');
                $data_array[$key]['edit_time'] = date('Y-m-d');
                unset($data_array[$key]['add_node_user_select']);
            }

            if(isset($value['edit_node_user_select']) && $value['edit_node_user_select'] == 'true'){
                $data_array[$key]['edit_node_user'] = session('username') ? session('username'):'客户';
                $data_array[$key]['edit_time'] = date('Y-m-d');
                unset($data_array[$key]['edit_node_user_select']);
            }

        }
        //dump($data_array);exit;
        $json_data = json_encode($data_array);
        $groupmindModel->mind_json = $json_data;
        $res = $groupmindModel->save();
        if($res >= 0){
            $ret['data'] = '';
            $ret['code'] = 0;
            $ret['msg']  = '保存成功';
        }else{
            $ret['data'] = '';
            $ret['code'] = -1;
            $ret['msg']  = '保存失败';
        }
        return $ret;
    }

    public function create(){
        $manage = input('param.manage');
        $id = input('param.id');
        $timetype = input('param.timetype');
        $meed_back = false;
        if(isset($timetype) && $timetype != 0){
            $oneday = 24 * 60 * 60 * $timetype;
            $meed_back = true;
        }

        $manage = isset($manage)?$manage : 0;
        $groupmindModel = new GroupmindModel();
        if(isset($id) && !empty($id)){
            $this->assign('id',$id);
            $save_type = 'edit';
            $groupmindModel = GroupmindModel::get($id);
            $mind_data = $groupmindModel->mind_json;

            $mind_data = json_decode($mind_data,true);

            foreach ($mind_data as $key => $value){
                if(isset($value['background-color'])){
                    unset($mind_data[$key]['background-color']);
                }
                if($meed_back === true && isset($value['edit_time'])){
                    $edite_time = strtotime($value['edit_time']);
                    if(($edite_time + $oneday) > time()){
                        $mind_data[$key]['background-color'] = 'red';
                    }
                }
                if(isset($value['price'])){
                    $temp_prcie = $value['price'];
                }else{
                    $temp_prcie = "0.00";
                    $mind_data[$key]['price'] = 0.00;
                }
                if($manage == 1){
                    $is_h = strpos($value['topic'],"/");
                    if(!$is_h){
                        $mind_data[$key]['topic'] = $mind_data[$key]['topic'].'/'.$temp_prcie;
                    }
                }

            }

            //dump($mind_data);exit;
            $mind_data = json_encode($mind_data);

        }else{
            $this->assign('id',0);
            $save_type = 'add';
            //$mind_data = $groupmindModel->createDefaltNote();
            //$mind_data = json_encode($mind_data);
            $mind_data = '[]';
        }
        if($groupmindModel->is_edit_mind == null){
            $this->assign('is_edit_mind',0);
        }else{
            $this->assign('is_edit_mind',$groupmindModel->is_edit_mind);
        }
        $this->assign('manage',$manage);
        $this->assign('save_type',$save_type);
        $this->assign('mind_data',$mind_data);
        return $this->fetch();
    }

    public function saveMind(){
        $param = input('param.');
        $groupmindModel = GroupmindModel::get($param['id']);

        $data_array = json_decode($param['data'],true);
        foreach ($data_array as $key => $value){
            if(isset($value['background-color'])){
                dump('background-color');
                unset($data_array[$key]['background-color']);
            }

            $is_h = strpos($value['topic'],"/");
            if($is_h){
                $data_array[$key]['only_topic'] = substr($value['topic'],0,$is_h);
                $data_array[$key]['topic'] = substr($value['topic'],0,$is_h);
            }

            if(isset($value['add_node_user_select']) && $value['add_node_user_select'] == 'true'){
                $data_array[$key]['add_time'] = date('Y-m-d');
                $data_array[$key]['edit_time'] = date('Y-m-d');
                unset($data_array[$key]['add_node_user_select']);
            }

            if(isset($value['edit_node_user_select']) && $value['edit_node_user_select'] == 'true'){
                $data_array[$key]['edit_node_user'] = session('username') ? session('username'):'客户';
                $data_array[$key]['edit_time'] = date('Y-m-d');
                unset($data_array[$key]['edit_node_user_select']);
            }
        }

        //dump($data_array);exit;
        //dump($data_array);exit;
        $json_data = json_encode($data_array);
        $groupmindModel->mind_json = $json_data;
        $res = $groupmindModel->save();
        if($res >= 0){
            $ret['data'] = '';
            $ret['code'] = 0;
            $ret['msg']  = '保存成功';
        }else{
            $ret['data'] = '';
            $ret['code'] = -1;
            $ret['msg']  = '保存失败';
        }
        return $ret;
    }

    public function phpword(){
        $id = input('param.id');
        $manage = isset($manage)?$manage : 0;
        if(isset($id) && !empty($id)){
            $groupmindModel = GroupmindModel::get($id);
            $mind_data = json_decode($groupmindModel->mind_json,true);
        }
//dump($groupmindModel->toArray());exit;
        switch ($groupmindModel->show_price){
            case 0 :
                $this->createWordByPrice_0($groupmindModel,$mind_data);
                break;
            case 1 :
                $this->createWordByPrice_1($groupmindModel,$mind_data);
                break;
            case 2 :
                $this->createWordByPrice_2($groupmindModel,$mind_data);
                break;
        }


    }

    //只显示总价
    protected function createWordByPrice_0($groupmindModel,$mind_data){
        $phpWord = new \PhpOffice\PhpWord\PhpWord();

        $section = $phpWord->addSection(array('pageNumberingStart' => 1));

        // 页眉
        $header = $section->addHeader();
        $header->addImage('static/admin/img/header.png', array('width' => 460, 'height' => 80, 'alignment' => \PhpOffice\PhpWord\SimpleType\Jc::CENTER));
        $section->addTextBreak(2);
        $phpWord->addTitleStyle(2, array('bold' => true, 'size' => 20, 'name' => 'Arial', 'Color' => '333'), array('align' => 'center'));
        $section->addTitle("公司报价单", 2);
        $section->addTextBreak(2);

        $tableStyle = array(
            'cellMargin' => 100,
            'alignment' => \PhpOffice\PhpWord\SimpleType\JcTable::CENTER,
            'borderSize' => 6,
        );
        $fancyTableFirstRowStyle = array('borderBottomSize' => 18, 'borderBottomColor' => 'ffffff', 'bgColor' => 'ffffff');

        $phpWord->addTableStyle('mytable', $tableStyle, $fancyTableFirstRowStyle);

        $table1 = $section->addTable('mytable');
        $cellRowSpan = array('vMerge' => 'restart', 'valign' => 'center', 'borderLeftSize' => 0, 'borderLeftColor' => 'ffffff', 'borderRightSize' => 0, 'borderRightColor' => 'ffffff',);
        $cellRowSpan_text = array('vMerge' => 'restart', 'valign' => 'center', 'borderLeftSize' => 0, 'cellMarginLeft' => 5, 'borderLeftColor' => 'ffffff', 'borderRightSize' => 0, 'borderRightColor' => 'ffffff',);
        $cellHCentered = array('align' => 'left');
        $cellHCentered_text = array('align' => 'center'); //居中
        $table1->addRow(900);
        $table1->addCell(4500, $cellRowSpan)->addText('收件公司：', null, $cellHCentered_text); //设置该列可以跨行，且样式居中
        $table1->addCell(4500, $cellRowSpan_text)->addText($groupmindModel->company_addressee, null, $cellHCentered);
        $table1->addCell(4500, $cellRowSpan)->addText('发件人：', null, $cellHCentered_text);
        $table1->addCell(4500, $cellRowSpan_text)->addText($groupmindModel->sender, null, $cellHCentered);
        $table1->addRow(900);
        $table1->addCell(4500, $cellRowSpan)->addText('发件公司：', null, $cellHCentered_text);
        $table1->addCell(4500, $cellRowSpan_text)->addText($groupmindModel->company_sender, null, $cellHCentered);
        $table1->addCell(4500, $cellRowSpan)->addText('日期：', null, $cellHCentered_text);
        $table1->addCell(4500, $cellRowSpan_text)->addText(date('Y-m-d', strtotime($groupmindModel->date)), null, $cellHCentered);

        $table1->addRow(900);
        $table1->addCell(4500, $cellRowSpan)->addText('手机：', null, $cellHCentered_text);
        $table1->addCell(4500, $cellRowSpan)->addText($groupmindModel->mobile, null, $cellHCentered);
        $table1->addCell(4500, $cellRowSpan)->addText('地址：', null, $cellHCentered_text);
        $table1->addCell(4500, $cellRowSpan)->addText($groupmindModel->address, null, $cellHCentered);

        $table1->addRow(900);
        $table1->addCell(4500, $cellRowSpan)->addText('固定电话：', null, $cellHCentered_text);
        $table1->addCell(4500, $cellRowSpan)->addText($groupmindModel->tel, null, $cellHCentered);
        $table1->addCell(4500, $cellRowSpan)->addText('主题：', null, $cellHCentered_text);
        $table1->addCell(4500, $cellRowSpan)->addText($groupmindModel->subject, null, $cellHCentered);
        $section->addTextBreak(2);

        $section->addText('感谢您对本公司的信任和支持，您需要的报价如下:', array('bold' => true, 'size' => 16));
        $section->addTextBreak(2);

        //功能模块
        $model_list = array();
        //硬件设备
        $hardware_list = array();
        $list = array();
        foreach ($mind_data as $key => $value) {
            if ($value['id'] == 'root') {
                $total_price = $value['price'];
                $root_name = $value['topic'];
            }

            if (isset($mind_data[$key]['parentid']) && ($mind_data[$key]['parentid'] == 'sub1')) {
                $is_h = strpos($value['topic'], "/");
                if ($is_h) {
                    $value['topic'] = substr($value['topic'], 0, $is_h);
                }
                $model_list[] = $value;
            }
        }

        $fancyTableStyleName = 'price_table';
        $fancyTableStyle = array('borderSize' => 6, 'borderColor' => '003322', 'cellMargin' => 80, 'alignment' => \PhpOffice\PhpWord\SimpleType\JcTable::CENTER);
        $fancyTableFirstRowStyle = array('borderBottomSize' => 18, 'borderBottomColor' => '0000FF', 'bgColor' => '#003322');
        $fancyTableCellStyle = array('valign' => 'center', 'align' => 'center',);
        $fancyTableCellBtlrStyle = array('valign' => 'center', 'textDirection' => \PhpOffice\PhpWord\Style\Cell::TEXT_DIR_BTLR);
        $fancyTableFontStyle = array('bold' => true, 'valign' => 'center', 'align' => 'center');
        $styleTable = array('borderSize' => 6, 'borderColor' => '999999');
        $phpWord->addTableStyle($fancyTableStyleName, $styleTable);
        $table_y = $section->addTable($fancyTableStyleName);

        $cellColSpan = array('valign' => 'center', 'gridSpan' => 8, 'valign' => 'center');

        $where['isdelete'] = 0;
        $where['id'] = $groupmindModel->combo_id;
        $comboname_res = CombonameModel::where($where)->field('first_name,second_name,thirdly_name')->find();
        $comboname_array = [
            '0' => $comboname_res['first_name'],
            '1' => $comboname_res['second_name'],
            '2' => $comboname_res['thirdly_name'],
        ];


        $hardware_list_width = 5800;
        if ($groupmindModel->combo_type == 0) {
            $hardware_list_width = 5800;
        } else if ($groupmindModel->combo_type == 1) {
            $hardware_list_width = 2900;
        } else if ($groupmindModel->combo_type == 2) {
            $hardware_list_width = 1933;
        }

        foreach ($mind_data as $key => $value) {
            if (isset($mind_data[$key]['parentid']) && ($mind_data[$key]['parentid'] == 'sub2')) {
                $hardware_list[] = $value;
            }
        }

        //套餐价格
        $combo1_total_price = 0;
        $combo2_total_price = 0;
        $combo3_total_price = 0;
        foreach ($hardware_list as $key => $value) {
            if (isset($value['combo1']) && $value['combo1'] == 'true') {
                $hardware_list[$key]['combo1'] = '✔';
                $combo1_total_price += $value['price'];
            } else {
                $hardware_list[$key]['combo1'] = '';
            }
            if (isset($value['combo2']) && $hardware_list[$key]['combo2'] == 'true') {
                $hardware_list[$key]['combo2'] = '✔';
                $combo2_total_price += $value['price'];
            } else {
                $hardware_list[$key]['combo2'] = '';
            }
            if (isset($value['combo3']) && $hardware_list[$key]['combo3'] == 'true') {
                $hardware_list[$key]['combo3'] = '✔';
                $combo3_total_price += $value['price'];
            } else {
                $hardware_list[$key]['combo3'] = '';
            }
        }

        if (!empty($hardware_list)) {
            $table_y->addRow(500);
            $table_y->addCell(12000, $cellColSpan)->addText('硬件设备', $fancyTableFontStyle, $fancyTableFontStyle);

            $table_y->addRow(500);
            $table_y->addCell(5700, $fancyTableCellStyle)->addText('品名/型号', $fancyTableFontStyle, $fancyTableFontStyle);
            $table_y->addCell(150, $fancyTableCellStyle)->addText('单位', $fancyTableFontStyle, $fancyTableFontStyle);
            $table_y->addCell(100, $fancyTableCellStyle)->addText('单价（元）', $fancyTableFontStyle, $fancyTableFontStyle);
            $table_y->addCell(100, $fancyTableCellStyle)->addText('数量', $fancyTableFontStyle, $fancyTableFontStyle);
            /*$table_y->addCell(150, $fancyTableCellStyle)->addText('金额（元）', $fancyTableFontStyle,$fancyTableFontStyle);*/

            for ($i = 0; $i <= $groupmindModel->combo_type; $i++) {
                $table_y->addCell($hardware_list_width, $fancyTableCellStyle)->addText($comboname_array[$i], $fancyTableFontStyle, $fancyTableFontStyle);
            }

            $cellColSpan = array('valign' => 'center', 'gridSpan' => 8, 'valign' => 'center');

            foreach ($hardware_list as $key => $value) {
                $table_y->addRow(500);
                $table_y->addCell(2800, $fancyTableCellStyle)->addText($value['only_topic'], $fancyTableCellStyle, $fancyTableCellStyle);
                $table_y->addCell(2200, $fancyTableCellStyle)->addText($value['hardware_unit'], $fancyTableCellStyle, $fancyTableCellStyle);
                $table_y->addCell(2200, $fancyTableCellStyle)->addText($value['hardware_price'], $fancyTableCellStyle, $fancyTableCellStyle);
                $table_y->addCell(2200, $fancyTableCellStyle)->addText($value['hardware_num'], $fancyTableCellStyle, $fancyTableCellStyle);
                /*$table_y->addCell(2200, $fancyTableCellStyle)->addText($value['price'],$fancyTableCellStyle,$fancyTableCellStyle);*/
                if ($groupmindModel->combo_type == 0) {
                    $table_y->addCell($hardware_list_width, $fancyTableCellStyle)->addText($value['combo1'], $fancyTableCellStyle, $fancyTableCellStyle);
                } else if ($groupmindModel->combo_type == 1) {
                    $table_y->addCell($hardware_list_width, $fancyTableCellStyle)->addText($value['combo1'], $fancyTableCellStyle, $fancyTableCellStyle);
                    $table_y->addCell($hardware_list_width, $fancyTableCellStyle)->addText($value['combo2'], $fancyTableCellStyle, $fancyTableCellStyle);
                } else if ($groupmindModel->combo_type == 2) {
                    $table_y->addCell($hardware_list_width, $fancyTableCellStyle)->addText($value['combo1'], $fancyTableCellStyle, $fancyTableCellStyle);
                    $table_y->addCell($hardware_list_width, $fancyTableCellStyle)->addText($value['combo2'], $fancyTableCellStyle, $fancyTableCellStyle);
                    $table_y->addCell($hardware_list_width, $fancyTableCellStyle)->addText($value['combo3'], $fancyTableCellStyle, $fancyTableCellStyle);
                } else {
                    $table_y->addCell(2000, $fancyTableCellStyle)->addText($value['combo1'], $fancyTableCellStyle, $fancyTableCellStyle);
                }
            }
        }

        //模块部分
        $fancyTableStyleName = 'price_table';
        $styleTable = array('borderSize' => 6, 'borderColor' => '999999');
        $fancyTableStyle = array('borderSize' => 6, 'borderColor' => '006699', 'cellMargin' => 80, 'alignment' => \PhpOffice\PhpWord\SimpleType\JcTable::CENTER);
        $fancyTableFirstRowStyle = array('borderBottomSize' => 18, 'borderBottomColor' => '0000FF', 'bgColor' => '66BBFF');
        $fancyTableCellBtlrStyle = array('valign' => 'center', 'textDirection' => \PhpOffice\PhpWord\Style\Cell::TEXT_DIR_BTLR);
        $fancyTableFontStyle = array('bold' => true, 'align' => 'center', 'valign' => "center");

        $phpWord->addTableStyle($fancyTableStyleName, $styleTable);
        $section->addTextBreak(2);
        $table = $section->addTable($fancyTableStyleName);

        $cellColSpan_r = array('valign' => 'center', 'gridSpan' => 6, 'valign' => 'center');
        $table->addRow(500);
        $table->addCell(12000, $cellColSpan_r)->addText('功能模块', $fancyTableFontStyle, $fancyTableFontStyle);
        $model_list_width = 1100;
        if ($groupmindModel->combo_type == 0) {
            $model_list_width = 3300;
        } else if ($groupmindModel->combo_type == 1) {
            $model_list_width = 1650;
        } else if ($groupmindModel->combo_type == 2) {
            $model_list_width = 1100;
        }
        $table->addRow(500);
        $table->addCell(4200, $fancyTableCellStyle)->addText('模块', $fancyTableFontStyle, $fancyTableFontStyle);
        $table->addCell(4200, $fancyTableCellStyle)->addText('功能', $fancyTableFontStyle, $fancyTableFontStyle);
        //$table->addCell(3000, $fancyTableCellStyle)->addText('金额',$fancyTableFontStyle,$fancyTableFontStyle);



        for ($i = 0; $i <= $groupmindModel->combo_type; $i++) {
            $table->addCell($model_list_width, $fancyTableCellStyle)->addText($comboname_array[$i], $fancyTableFontStyle, $fancyTableFontStyle);
        }

        foreach ($model_list as $key => $value) {
            if (isset($value['combo1']) && $value['combo1'] == 'true') {
                $model_list[$key]['combo1'] = '✔';
                if (isset($value['editPrice']) && $value['editPrice'] == 'true') {
                    $combo1_total_price += $value['price'];
                }
            } else {
                $model_list[$key]['combo1'] = '';
            }

            if (isset($value['combo2']) && $value['combo2'] == 'true') {
                $model_list[$key]['combo2'] = '✔';
                if (isset($value['editPrice']) && $value['editPrice'] == 'true') {
                    $combo2_total_price += $value['price'];
                }
            } else {
                $model_list[$key]['combo2'] = '';
            }

            if (isset($value['combo3']) && $value['combo3'] == 'true') {
                $model_list[$key]['combo3'] = '✔';
                if (isset($value['editPrice']) && $value['editPrice'] == 'true') {
                    $combo3_total_price += $value['price'];
                }
            } else {
                $model_list[$key]['combo3'] = '';
            }

            foreach ($mind_data as $key1 => $value1) {
                if (isset($value1['parentid']) && $value1['parentid'] == $value['id']) {
                    $value1['modle'] = $value['topic'];

                    if (isset($value1['combo1']) && $value1['combo1'] == 'true') {
                        if (!isset($value['editPrice']) || $value['editPrice'] == 'false') {
                            $combo1_total_price += $value1['price'];
                        }
                        $value1['combo1'] = '✔';
                    } else {
                        $value1['combo1'] = '';
                    }

                    if (isset($value1['combo2']) && $value1['combo2'] == 'true') {
                        $value1['combo2'] = '✔';
                        if (!isset($value['editPrice']) || $value['editPrice'] == 'false') {
                            $combo2_total_price += $value1['price'];
                        }
                    } else {
                        $value1['combo2'] = '';
                    }

                    if (isset($value1['combo3']) && $value1['combo3'] == 'true') {
                        $value1['combo3'] = '✔';
                        if (!isset($value['editPrice']) || $value['editPrice'] == 'false') {
                            $combo3_total_price += $value1['price'];
                        }
                    } else {
                        $value1['combo3'] = '';
                    }
                    $list[] = $value1;

                    $model_list[$key]['child'][] = $value1;
                }
            }
        }
        $tableStyleCell = array('vMerge' => 'restart', 'valign' => "center", 'align' => 'center');
        $tableStyleText = array('align' => 'center', 'valign' => "center");
        $tableStyleMergeRestart = array('vMerge' => 'restart', 'valign' => "center", 'align' => 'center');
        $tableStyleMergeContinue = array('vMerge' => 'continue', 'valign' => "center", 'align' => 'center');

        foreach ($model_list as $key => $value) {
            $editPrice = false;
            if (isset($value['editPrice']) && $value['editPrice'] == 'true') {
                $editPrice = true;
            }
            $temp_velue = 0;
            if (!empty($value['child'])) {
                foreach ($value['child'] as $key1 => $value1) {
                    $table->addRow(500);
                    if ($temp_velue === 0) {
                        $table->addCell(4200, $tableStyleMergeRestart)->addText($value1['modle'], $tableStyleText, $tableStyleText);
                    } else if ($temp_velue === 1) {
                        $table->addCell(null, $tableStyleMergeContinue);
                    }
                    if (isset($value1['only_topic'])) {
                        $table->addCell(4200, $tableStyleCell)->addText($value1['only_topic'], $tableStyleText, $tableStyleText);
                    } else {
                        $table->addCell(4200, $tableStyleCell)->addText($value1['topic'], $tableStyleText, $tableStyleText);
                    }

                    if ($temp_velue === 0 && $editPrice === true) {
                        //$table->addCell(3000,$tableStyleMergeRestart)->addText($value['price'],$tableStyleText,$tableStyleText);

                        if ($groupmindModel->combo_type == 0) {
                            $table->addCell($model_list_width, $tableStyleMergeRestart)->addText($value['combo1'], $tableStyleText, $tableStyleText);
                        } else if ($groupmindModel->combo_type == 1) {
                            $table->addCell($model_list_width, $tableStyleMergeRestart)->addText($value['combo1'], $tableStyleText, $tableStyleText);
                            $table->addCell($model_list_width, $tableStyleMergeRestart)->addText($value['combo2'], $tableStyleText, $tableStyleText);
                        } else if ($groupmindModel->combo_type == 2) {
                            $table->addCell($model_list_width, $tableStyleMergeRestart)->addText($value['combo1'], $tableStyleText, $tableStyleText);
                            $table->addCell($model_list_width, $tableStyleMergeRestart)->addText($value['combo2'], $tableStyleText, $tableStyleText);
                            $table->addCell($model_list_width, $tableStyleMergeRestart)->addText($value['combo3'], $tableStyleText, $tableStyleText);
                        } else {
                            $table->addCell($model_list_width, $tableStyleMergeRestart)->addText($value['combo1'], $tableStyleText, $tableStyleText);
                        }

                    } else if ($temp_velue === 1 && $editPrice === true) {
                        //$table->addCell(null, $tableStyleMergeContinue);

                        if ($groupmindModel->combo_type == 0) {
                            $table->addCell(null, $tableStyleMergeContinue);
                        } else if ($groupmindModel->combo_type == 1) {
                            $table->addCell(null, $tableStyleMergeContinue);
                            $table->addCell(null, $tableStyleMergeContinue);
                        } else if ($groupmindModel->combo_type == 2) {
                            $table->addCell(null, $tableStyleMergeContinue);
                            $table->addCell(null, $tableStyleMergeContinue);
                            $table->addCell(null, $tableStyleMergeContinue);
                        } else {
                            $table->addCell(null, $tableStyleMergeContinue);
                        }

                    } else {
//                        if (!isset($value1['price'])) {
//                            $value1['price'] = 0.00;
//                        }
                        //$table->addCell(3000,$tableStyleCell)->addText($value1['price'],$tableStyleText,$tableStyleText);
                        if ($groupmindModel->combo_type == 0) {
                            $table->addCell($model_list_width, $tableStyleCell)->addText($value1['combo1'], $tableStyleText, $tableStyleText);
                        } else if ($groupmindModel->combo_type == 1) {
                            $table->addCell($model_list_width, $tableStyleCell)->addText($value1['combo1'], $tableStyleText, $tableStyleText);
                            $table->addCell($model_list_width, $tableStyleCell)->addText($value1['combo2'], $tableStyleText, $tableStyleText);
                        } else if ($groupmindModel->combo_type == 2) {
                            $table->addCell($model_list_width, $tableStyleCell)->addText($value1['combo1'], $tableStyleText, $tableStyleText);
                            $table->addCell($model_list_width, $tableStyleCell)->addText($value1['combo2'], $tableStyleText, $tableStyleText);
                            $table->addCell($model_list_width, $tableStyleCell)->addText($value1['combo3'], $tableStyleText, $tableStyleText);
                        } else {
                            $table->addCell($model_list_width, $tableStyleCell)->addText($value1['combo1'], $tableStyleText, $tableStyleText);
                        }
                    }
                    $temp_velue = 1;
                }
            }
        }

        $table->addRow(500);
        $table->addCell($model_list_width, array('valign' => 'center', 'valign' => 'center'))->addText("总计：", $tableStyleText, $tableStyleText);
        $table->addCell($model_list_width, $tableStyleCell)->addText($total_price, $tableStyleText, $tableStyleText);

        if ($groupmindModel->combo_type == 0) {
            $table->addCell(300, $tableStyleCell)->addText($combo1_total_price, $tableStyleText, $tableStyleText);
        } else if ($groupmindModel->combo_type == 1) {
            $table->addCell(300, $tableStyleCell)->addText($combo1_total_price, $tableStyleText, $tableStyleText);
            $table->addCell(300, $tableStyleCell)->addText($combo2_total_price, $tableStyleText, $tableStyleText);
        } else if ($groupmindModel->combo_type == 2) {
            $table->addCell(300, $tableStyleCell)->addText($combo1_total_price, $tableStyleText, $tableStyleText);
            $table->addCell(300, $tableStyleCell)->addText($combo2_total_price, $tableStyleText, $tableStyleText);
            $table->addCell(300, $tableStyleCell)->addText($combo3_total_price, $tableStyleText, $tableStyleText);
        } else {
            $table->addCell(300, $tableStyleCell)->addText($combo1_total_price, $tableStyleText, $tableStyleText);
        }

        $root_name = $groupmindModel->name . '报价单-' . date('Ymd');
        $file = $root_name . '.docx';
        if (ob_get_length()) ob_end_clean();
        header("Content-Description: File Transfer");
        header('Content-Disposition: attachment; filename="' . $file . '"');
        header('Content-Type: application/vnd.openxmlformats-officedocument.wordprocessingml.document');
        header('Content-Transfer-Encoding: binary');
        header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
        header('Expires: 0');
        ob_start(); //打开缓冲区
        $xmlWriter = \PhpOffice\PhpWord\IOFactory::createWriter($phpWord, 'Word2007');
        $xmlWriter->save("php://output", 'Word2007', true);
    }

    //只显示合并价
    protected function createWordByPrice_1($groupmindModel,$mind_data){
        $phpWord = new \PhpOffice\PhpWord\PhpWord();

        $section = $phpWord->addSection(array('pageNumberingStart' => 1));

        // 页眉
        $header = $section->addHeader();
        $header->addImage('static/admin/img/header.png', array('width' => 460, 'height' => 80, 'alignment' => \PhpOffice\PhpWord\SimpleType\Jc::CENTER));
        $section->addTextBreak(2);
        $phpWord->addTitleStyle(2, array('bold' => true, 'size' => 20, 'name' => 'Arial', 'Color' => '333'), array('align' => 'center'));
        $section->addTitle("公司报价单", 2);
        $section->addTextBreak(2);

        $tableStyle = array(
            'cellMargin' => 100,
            'alignment' => \PhpOffice\PhpWord\SimpleType\JcTable::CENTER,
            'borderSize' => 6,
        );
        $fancyTableFirstRowStyle = array('borderBottomSize' => 18, 'borderBottomColor' => 'ffffff', 'bgColor' => 'ffffff');

        $phpWord->addTableStyle('mytable', $tableStyle, $fancyTableFirstRowStyle);

        $table1 = $section->addTable('mytable');
        $cellRowSpan = array('vMerge' => 'restart', 'valign' => 'center','borderLeftSize'=>0, 'borderLeftColor'=>'ffffff','borderRightSize'=> 0,'borderRightColor'=>'ffffff',);
        $cellRowSpan_text = array('vMerge' => 'restart', 'valign' => 'center','borderLeftSize'=>0,'cellMarginLeft'=>5, 'borderLeftColor'=>'ffffff','borderRightSize'=> 0,'borderRightColor'=>'ffffff',);
        $cellHCentered = array('align' => 'left');
        $cellHCentered_text = array('align' => 'center'); //居中
        $table1->addRow(900);
        $table1->addCell(4500, $cellRowSpan)->addText('收件公司：',null, $cellHCentered_text); //设置该列可以跨行，且样式居中
        $table1->addCell(4500, $cellRowSpan_text)->addText($groupmindModel->company_addressee,null, $cellHCentered);
        $table1->addCell(4500, $cellRowSpan)->addText('发件人：',null, $cellHCentered_text);
        $table1->addCell(4500, $cellRowSpan_text)->addText($groupmindModel->sender,null, $cellHCentered);
        $table1->addRow(900);
        $table1->addCell(4500, $cellRowSpan)->addText('发件公司：',null, $cellHCentered_text);
        $table1->addCell(4500, $cellRowSpan_text)->addText($groupmindModel->company_sender,null, $cellHCentered);
        $table1->addCell(4500, $cellRowSpan)->addText('日期：',null, $cellHCentered_text);
        $table1->addCell(4500, $cellRowSpan_text)->addText(date('Y-m-d',strtotime($groupmindModel->date)),null, $cellHCentered);

        $table1->addRow(900);
        $table1->addCell(4500, $cellRowSpan)->addText('手机：',null, $cellHCentered_text);
        $table1->addCell(4500, $cellRowSpan)->addText($groupmindModel->mobile,null, $cellHCentered);
        $table1->addCell(4500, $cellRowSpan)->addText('地址：',null, $cellHCentered_text);
        $table1->addCell(4500, $cellRowSpan)->addText($groupmindModel->address,null, $cellHCentered);

        $table1->addRow(900);
        $table1->addCell(4500, $cellRowSpan)->addText('固定电话：',null, $cellHCentered_text);
        $table1->addCell(4500, $cellRowSpan)->addText($groupmindModel->tel,null, $cellHCentered);
        $table1->addCell(4500, $cellRowSpan)->addText('主题：',null, $cellHCentered_text);
        $table1->addCell(4500, $cellRowSpan)->addText($groupmindModel->subject,null, $cellHCentered);
        $section->addTextBreak(2);

        $section->addText('感谢您对本公司的信任和支持，您需要的报价如下:',array('bold' => true,'size' => 16));
        $section->addTextBreak(2);

        //功能模块
        $model_list = array();
        //硬件设备
        $hardware_list = array();
        $list = array();
        foreach ($mind_data as $key => $value) {
            if($value['id'] == 'root'){
                $total_price = $value['price'];
                $root_name = $value['topic'];
            }

            if (isset($mind_data[$key]['parentid']) && ($mind_data[$key]['parentid'] == 'sub1')) {
                $is_h = strpos($value['topic'],"/");
                if($is_h){
                    $value['topic'] = substr($value['topic'],0,$is_h);
                }
                $model_list[] = $value;
            }
        }

        $fancyTableStyleName = 'price_table';
        $fancyTableStyle = array('borderSize' => 6, 'borderColor' => '003322', 'cellMargin' => 80, 'alignment' => \PhpOffice\PhpWord\SimpleType\JcTable::CENTER);
        $fancyTableFirstRowStyle = array('borderBottomSize' => 18, 'borderBottomColor' => '0000FF', 'bgColor' => '#003322');
        $fancyTableCellStyle = array('valign' => 'center','align' => 'center',);
        $fancyTableCellBtlrStyle = array('valign' => 'center', 'textDirection' => \PhpOffice\PhpWord\Style\Cell::TEXT_DIR_BTLR);
        $fancyTableFontStyle = array('bold' => true,'valign' => 'center','align' => 'center');
        $styleTable = array('borderSize' => 6, 'borderColor' => '999999');
        $phpWord->addTableStyle($fancyTableStyleName, $styleTable);
        $table_y = $section->addTable($fancyTableStyleName);

        $cellColSpan = array('valign' => 'center','gridSpan' => 8, 'valign' => 'center');

        $where['isdelete']=0;
        $where['id']=$groupmindModel->combo_id;
        $comboname_res = CombonameModel::where($where)->field('first_name,second_name,thirdly_name')->find();
        $comboname_array = [
            '0'=>$comboname_res['first_name'],
            '1'=>$comboname_res['second_name'],
            '2'=>$comboname_res['thirdly_name'],
        ];


        $hardware_list_width = 5800;
        if($groupmindModel->combo_type == 0){
            $hardware_list_width = 5800;
        }else if($groupmindModel->combo_type == 1){
            $hardware_list_width = 2900;
        }else if($groupmindModel->combo_type == 2){
            $hardware_list_width = 1933;
        }

        foreach ($mind_data as $key => $value) {
            if (isset($mind_data[$key]['parentid']) && ($mind_data[$key]['parentid'] == 'sub2')) {
                $hardware_list[] = $value;
            }
        }

        //套餐价格
        $combo1_total_price = 0;
        $combo2_total_price = 0;
        $combo3_total_price = 0;
        foreach ($hardware_list as $key => $value) {
            if(isset($value['combo1']) && $value['combo1'] == 'true'){
                $hardware_list[$key]['combo1'] = '✔';
                $combo1_total_price += $value['price'];
            }else{
                $hardware_list[$key]['combo1'] = '';
            }
            if(isset($value['combo2']) && $hardware_list[$key]['combo2'] == 'true'){
                $hardware_list[$key]['combo2'] = '✔';
                $combo2_total_price += $value['price'];
            }else{
                $hardware_list[$key]['combo2'] = '';
            }
            if(isset($value['combo3']) && $hardware_list[$key]['combo3'] == 'true'){
                $hardware_list[$key]['combo3'] = '✔';
                $combo3_total_price += $value['price'];
            }else{
                $hardware_list[$key]['combo3'] = '';
            }
        }

        if(!empty($hardware_list)){
            $table_y->addRow(500);
            $table_y->addCell(12000, $cellColSpan)->addText('硬件设备', $fancyTableFontStyle,$fancyTableFontStyle);

            $table_y->addRow(500);
            $table_y->addCell(5700, $fancyTableCellStyle)->addText('品名/型号', $fancyTableFontStyle,$fancyTableFontStyle);
            $table_y->addCell(150, $fancyTableCellStyle)->addText('单位', $fancyTableFontStyle,$fancyTableFontStyle);
            $table_y->addCell(100, $fancyTableCellStyle)->addText('单价（元）', $fancyTableFontStyle,$fancyTableFontStyle);
            $table_y->addCell(100, $fancyTableCellStyle)->addText('数量', $fancyTableFontStyle,$fancyTableFontStyle);
            $table_y->addCell(150, $fancyTableCellStyle)->addText('金额（元）', $fancyTableFontStyle,$fancyTableFontStyle);



            for ($i = 0;$i<=$groupmindModel->combo_type;$i++){
                $table_y->addCell($hardware_list_width, $fancyTableCellStyle)->addText($comboname_array[$i], $fancyTableFontStyle,$fancyTableFontStyle);
            }

            $cellColSpan = array('valign' => 'center','gridSpan' => 8, 'valign' => 'center');

            foreach ($hardware_list as $key => $value){
                $table_y->addRow(500);
                $table_y->addCell(2800, $fancyTableCellStyle)->addText($value['only_topic'],$fancyTableCellStyle,$fancyTableCellStyle);
                $table_y->addCell(2200, $fancyTableCellStyle)->addText($value['hardware_unit'],$fancyTableCellStyle,$fancyTableCellStyle);
                $table_y->addCell(2200, $fancyTableCellStyle)->addText($value['hardware_price'],$fancyTableCellStyle,$fancyTableCellStyle);
                $table_y->addCell(2200, $fancyTableCellStyle)->addText($value['hardware_num'],$fancyTableCellStyle,$fancyTableCellStyle);
                $table_y->addCell(2200, $fancyTableCellStyle)->addText($value['price'],$fancyTableCellStyle,$fancyTableCellStyle);
                if($groupmindModel->combo_type == 0){
                    $table_y->addCell($hardware_list_width, $fancyTableCellStyle)->addText($value['combo1'],$fancyTableCellStyle,$fancyTableCellStyle);
                }else if($groupmindModel->combo_type == 1){
                    $table_y->addCell($hardware_list_width, $fancyTableCellStyle)->addText($value['combo1'],$fancyTableCellStyle,$fancyTableCellStyle);
                    $table_y->addCell($hardware_list_width, $fancyTableCellStyle)->addText($value['combo2'],$fancyTableCellStyle,$fancyTableCellStyle);
                }else if($groupmindModel->combo_type == 2){
                    $table_y->addCell($hardware_list_width, $fancyTableCellStyle)->addText($value['combo1'],$fancyTableCellStyle,$fancyTableCellStyle);
                    $table_y->addCell($hardware_list_width, $fancyTableCellStyle)->addText($value['combo2'],$fancyTableCellStyle,$fancyTableCellStyle);
                    $table_y->addCell($hardware_list_width, $fancyTableCellStyle)->addText($value['combo3'],$fancyTableCellStyle,$fancyTableCellStyle);
                }else{
                    $table_y->addCell(2000, $fancyTableCellStyle)->addText($value['combo1'],$fancyTableCellStyle,$fancyTableCellStyle);
                }
            }
        }

        //模块部分
        $fancyTableStyleName = 'price_table';
        $styleTable = array('borderSize' => 6, 'borderColor' => '999999');
        $fancyTableStyle = array('borderSize' => 6, 'borderColor' => '006699', 'cellMargin' => 80, 'alignment' => \PhpOffice\PhpWord\SimpleType\JcTable::CENTER);
        $fancyTableFirstRowStyle = array('borderBottomSize' => 18, 'borderBottomColor' => '0000FF', 'bgColor' => '66BBFF');
        $fancyTableCellBtlrStyle = array('valign' => 'center', 'textDirection' => \PhpOffice\PhpWord\Style\Cell::TEXT_DIR_BTLR);
        $fancyTableFontStyle = array('bold' => true,'align' => 'center','valign' => "center");

        $phpWord->addTableStyle($fancyTableStyleName, $styleTable);
        $section->addTextBreak(2);
        $table = $section->addTable($fancyTableStyleName);

        $cellColSpan_r = array('valign' => 'center','gridSpan' => 6, 'valign' => 'center');
        $table->addRow(500);
        $table->addCell(12000, $cellColSpan_r)->addText('功能模块', $fancyTableFontStyle,$fancyTableFontStyle);

        $table->addRow(500);
        $table->addCell(3000, $fancyTableCellStyle)->addText('模块',$fancyTableFontStyle,$fancyTableFontStyle);
        $table->addCell(3000, $fancyTableCellStyle)->addText('功能',$fancyTableFontStyle,$fancyTableFontStyle);
        $table->addCell(3000, $fancyTableCellStyle)->addText('金额',$fancyTableFontStyle,$fancyTableFontStyle);
        $model_list_width = 1000;
        if($groupmindModel->combo_type == 0){
            $model_list_width = 3000;
        }else if($groupmindModel->combo_type == 1){
            $model_list_width = 1500;
        }else if($groupmindModel->combo_type == 2){
            $model_list_width = 1000;
        }


        for ($i = 0;$i<=$groupmindModel->combo_type;$i++){
            $table->addCell($model_list_width, $fancyTableCellStyle)->addText($comboname_array[$i], $fancyTableFontStyle,$fancyTableFontStyle);
        }


        foreach ($model_list as $key => $value) {
            if(isset($value['combo1']) && $value['combo1'] == 'true'){
                $model_list[$key]['combo1'] = '✔';
                $combo1_total_price += $value['price'];
            }else{
                $model_list[$key]['combo1'] = '';
            }

            if(isset($value['combo2']) && $value['combo2'] == 'true'){
                $model_list[$key]['combo2'] = '✔';
                $combo2_total_price += $value['price'];

            }else{
                $model_list[$key]['combo2'] = '';
            }

            if(isset($value['combo3']) && $value['combo3'] == 'true'){
                $model_list[$key]['combo3'] = '✔';
                $combo3_total_price += $value['price'];
            }else{
                $model_list[$key]['combo3'] = '';
            }

            foreach ($mind_data as $key1 => $value1) {
                if (isset($value1['parentid']) && $value1['parentid'] == $value['id']) {
                    $value1['modle'] = $value['topic'];
                    $list[] = $value1;
                    $model_list[$key]['child'][] = $value1;
                }
            }
        }

        $tableStyleCell = array('vMerge' => 'restart', 'valign' => "center",'align' => 'center');
        $tableStyleText = array('align' => 'center','valign' => "center");
        $tableStyleMergeRestart = array('vMerge' => 'restart', 'valign' => "center",'align' => 'center');
        $tableStyleMergeContinue = array('vMerge' => 'continue','valign' => "center",'align' => 'center');

        foreach ($model_list as $key => $value){
            $editPrice = true;
            $temp_velue = 0;
            if(!empty($value['child'])){
                foreach ($value['child'] as $key1 => $value1){
                    $table->addRow(500);
                    if($temp_velue === 0){
                        $table->addCell(3000,$tableStyleMergeRestart)->addText($value1['modle'],$tableStyleText,$tableStyleText);
                    }else if($temp_velue === 1){
                        $table->addCell(null,$tableStyleMergeContinue);
                    }
                    if(isset($value1['only_topic'])){
                        $table->addCell(3000,$tableStyleCell)->addText($value1['only_topic'],$tableStyleText,$tableStyleText);
                    }else{
                        $table->addCell(3000,$tableStyleCell)->addText($value1['topic'],$tableStyleText,$tableStyleText);
                    }

                    if($temp_velue === 0){
                        $table->addCell(3000,$tableStyleMergeRestart)->addText($value['price'],$tableStyleText,$tableStyleText);

                        if($groupmindModel->combo_type == 0){
                            $table->addCell($model_list_width,$tableStyleMergeRestart)->addText($value['combo1'],$tableStyleText,$tableStyleText);
                        }else if($groupmindModel->combo_type == 1){
                            $table->addCell($model_list_width,$tableStyleMergeRestart)->addText($value['combo1'],$tableStyleText,$tableStyleText);
                            $table->addCell($model_list_width,$tableStyleMergeRestart)->addText($value['combo2'],$tableStyleText,$tableStyleText);
                        }else if($groupmindModel->combo_type == 2){
                            $table->addCell($model_list_width,$tableStyleMergeRestart)->addText($value['combo1'],$tableStyleText,$tableStyleText);
                            $table->addCell($model_list_width,$tableStyleMergeRestart)->addText($value['combo2'],$tableStyleText,$tableStyleText);
                            $table->addCell($model_list_width,$tableStyleMergeRestart)->addText($value['combo3'],$tableStyleText,$tableStyleText);
                        }else{
                            $table->addCell($model_list_width,$tableStyleMergeRestart)->addText($value['combo1'],$tableStyleText,$tableStyleText);
                        }

                    }else if($temp_velue === 1 && $editPrice === true){
                        $table->addCell(null,$tableStyleMergeContinue);

                        if($groupmindModel->combo_type == 0){
                            $table->addCell(null,$tableStyleMergeContinue);
                        }else if($groupmindModel->combo_type == 1){
                            $table->addCell(null,$tableStyleMergeContinue);
                            $table->addCell(null,$tableStyleMergeContinue);
                        }else if($groupmindModel->combo_type == 2){
                            $table->addCell(null,$tableStyleMergeContinue);
                            $table->addCell(null,$tableStyleMergeContinue);
                            $table->addCell(null,$tableStyleMergeContinue);
                        }else{
                            $table->addCell(null,$tableStyleMergeContinue);
                        }

                    }else{
                        if(!isset($value1['price'])){
                            $value1['price'] = 0.00;
                        }
                        $table->addCell(3000,$tableStyleCell)->addText($value1['price'],$tableStyleText,$tableStyleText);
                        if($groupmindModel->combo_type == 0){
                            $table->addCell($model_list_width,$tableStyleCell)->addText($value1['combo1'],$tableStyleText,$tableStyleText);
                        }else if($groupmindModel->combo_type == 1){
                            $table->addCell($model_list_width,$tableStyleCell)->addText($value1['combo1'],$tableStyleText,$tableStyleText);
                            $table->addCell($model_list_width,$tableStyleCell)->addText($value1['combo2'],$tableStyleText,$tableStyleText);
                        }else if($groupmindModel->combo_type == 2){
                            $table->addCell($model_list_width,$tableStyleCell)->addText($value1['combo1'],$tableStyleText,$tableStyleText);
                            $table->addCell($model_list_width,$tableStyleCell)->addText($value1['combo2'],$tableStyleText,$tableStyleText);
                            $table->addCell($model_list_width,$tableStyleCell)->addText($value1['combo3'],$tableStyleText,$tableStyleText);
                        }else{
                            $table->addCell($model_list_width,$tableStyleCell)->addText($value1['combo1'],$tableStyleText,$tableStyleText);
                        }

                    }
                    $temp_velue = 1;
                }
            }
        }

        $table->addRow(500);
        $table->addCell($model_list_width,array('valign' => 'center','gridSpan' => 2, 'valign' => 'center'))->addText("总计：",$tableStyleText,$tableStyleText);
        $table->addCell($model_list_width,$tableStyleCell)->addText($total_price,$tableStyleText,$tableStyleText);

        if($groupmindModel->combo_type == 0){
            $table->addCell(300,$tableStyleCell)->addText($combo1_total_price,$tableStyleText,$tableStyleText);
        }else if($groupmindModel->combo_type == 1){
            $table->addCell(300,$tableStyleCell)->addText($combo1_total_price,$tableStyleText,$tableStyleText);
            $table->addCell(300,$tableStyleCell)->addText($combo2_total_price,$tableStyleText,$tableStyleText);
        }else if($groupmindModel->combo_type == 2){
            $table->addCell(300,$tableStyleCell)->addText($combo1_total_price,$tableStyleText,$tableStyleText);
            $table->addCell(300,$tableStyleCell)->addText($combo2_total_price,$tableStyleText,$tableStyleText);
            $table->addCell(300,$tableStyleCell)->addText($combo3_total_price,$tableStyleText,$tableStyleText);
        }else{
            $table->addCell(300,$tableStyleCell)->addText($combo1_total_price,$tableStyleText,$tableStyleText);
        }

        $root_name = $groupmindModel->name.'报价单-'.date('Ymd');
        $file =$root_name.'.docx';
        if(ob_get_length()) ob_end_clean();
        header("Content-Description: File Transfer");
        header('Content-Disposition: attachment; filename="' . $file . '"');
        header('Content-Type: application/vnd.openxmlformats-officedocument.wordprocessingml.document');
        header('Content-Transfer-Encoding: binary');
        header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
        header('Expires: 0');
        ob_start(); //打开缓冲区
        $xmlWriter = \PhpOffice\PhpWord\IOFactory::createWriter($phpWord, 'Word2007');
        $xmlWriter->save("php://output",'Word2007',true);
    }

    // 合并与细项并存
    protected function createWordByPrice_2($groupmindModel,$mind_data){
        $phpWord = new \PhpOffice\PhpWord\PhpWord();

        $section = $phpWord->addSection(array('pageNumberingStart' => 1));

        // 页眉
        $header = $section->addHeader();
        $header->addImage('static/admin/img/header.png', array('width' => 460, 'height' => 80, 'alignment' => \PhpOffice\PhpWord\SimpleType\Jc::CENTER));
        $section->addTextBreak(2);
        $phpWord->addTitleStyle(2, array('bold' => true, 'size' => 20, 'name' => 'Arial', 'Color' => '333'), array('align' => 'center'));
        $section->addTitle("公司报价单", 2);
        $section->addTextBreak(2);

        $tableStyle = array(
            'cellMargin' => 100,
            'alignment' => \PhpOffice\PhpWord\SimpleType\JcTable::CENTER,
            'borderSize' => 6,
        );
        $fancyTableFirstRowStyle = array('borderBottomSize' => 18, 'borderBottomColor' => 'ffffff', 'bgColor' => 'ffffff');

        $phpWord->addTableStyle('mytable', $tableStyle, $fancyTableFirstRowStyle);

        $table1 = $section->addTable('mytable');
        $cellRowSpan = array('vMerge' => 'restart', 'valign' => 'center','borderLeftSize'=>0, 'borderLeftColor'=>'ffffff','borderRightSize'=> 0,'borderRightColor'=>'ffffff',);
        $cellRowSpan_text = array('vMerge' => 'restart', 'valign' => 'center','borderLeftSize'=>0,'cellMarginLeft'=>5, 'borderLeftColor'=>'ffffff','borderRightSize'=> 0,'borderRightColor'=>'ffffff',);
        $cellHCentered = array('align' => 'left');
        $cellHCentered_text = array('align' => 'center'); //居中
        $table1->addRow(900);
        $table1->addCell(4500, $cellRowSpan)->addText('收件公司：',null, $cellHCentered_text); //设置该列可以跨行，且样式居中
        $table1->addCell(4500, $cellRowSpan_text)->addText($groupmindModel->company_addressee,null, $cellHCentered);
        $table1->addCell(4500, $cellRowSpan)->addText('发件人：',null, $cellHCentered_text);
        $table1->addCell(4500, $cellRowSpan_text)->addText($groupmindModel->sender,null, $cellHCentered);
        $table1->addRow(900);
        $table1->addCell(4500, $cellRowSpan)->addText('发件公司：',null, $cellHCentered_text);
        $table1->addCell(4500, $cellRowSpan_text)->addText($groupmindModel->company_sender,null, $cellHCentered);
        $table1->addCell(4500, $cellRowSpan)->addText('日期：',null, $cellHCentered_text);
        $table1->addCell(4500, $cellRowSpan_text)->addText(date('Y-m-d',strtotime($groupmindModel->date)),null, $cellHCentered);

        $table1->addRow(900);
        $table1->addCell(4500, $cellRowSpan)->addText('手机：',null, $cellHCentered_text);
        $table1->addCell(4500, $cellRowSpan)->addText($groupmindModel->mobile,null, $cellHCentered);
        $table1->addCell(4500, $cellRowSpan)->addText('地址：',null, $cellHCentered_text);
        $table1->addCell(4500, $cellRowSpan)->addText($groupmindModel->address,null, $cellHCentered);

        $table1->addRow(900);
        $table1->addCell(4500, $cellRowSpan)->addText('固定电话：',null, $cellHCentered_text);
        $table1->addCell(4500, $cellRowSpan)->addText($groupmindModel->tel,null, $cellHCentered);
        $table1->addCell(4500, $cellRowSpan)->addText('主题：',null, $cellHCentered_text);
        $table1->addCell(4500, $cellRowSpan)->addText($groupmindModel->subject,null, $cellHCentered);
        $section->addTextBreak(2);

        $section->addText('感谢您对本公司的信任和支持，您需要的报价如下:',array('bold' => true,'size' => 16));
        $section->addTextBreak(2);

        //功能模块
        $model_list = array();
        //硬件设备
        $hardware_list = array();
        $list = array();
        foreach ($mind_data as $key => $value) {
            if($value['id'] == 'root'){
                $total_price = $value['price'];
                $root_name = $value['topic'];
            }

            if (isset($mind_data[$key]['parentid']) && ($mind_data[$key]['parentid'] == 'sub1')) {
                $is_h = strpos($value['topic'],"/");
                if($is_h){
                    $value['topic'] = substr($value['topic'],0,$is_h);
                }
                $model_list[] = $value;
            }
        }

        $fancyTableStyleName = 'price_table';
        $fancyTableStyle = array('borderSize' => 6, 'borderColor' => '003322', 'cellMargin' => 80, 'alignment' => \PhpOffice\PhpWord\SimpleType\JcTable::CENTER);
        $fancyTableFirstRowStyle = array('borderBottomSize' => 18, 'borderBottomColor' => '0000FF', 'bgColor' => '#003322');
        $fancyTableCellStyle = array('valign' => 'center','align' => 'center',);
        $fancyTableCellBtlrStyle = array('valign' => 'center', 'textDirection' => \PhpOffice\PhpWord\Style\Cell::TEXT_DIR_BTLR);
        $fancyTableFontStyle = array('bold' => true,'valign' => 'center','align' => 'center');
        $styleTable = array('borderSize' => 6, 'borderColor' => '999999');
        $phpWord->addTableStyle($fancyTableStyleName, $styleTable);
        $table_y = $section->addTable($fancyTableStyleName);

        $cellColSpan = array('valign' => 'center','gridSpan' => 8, 'valign' => 'center');

        $where['isdelete']=0;
        $where['id']=$groupmindModel->combo_id;
        $comboname_res = CombonameModel::where($where)->field('first_name,second_name,thirdly_name')->find();
        $comboname_array = [
            '0'=>$comboname_res['first_name'],
            '1'=>$comboname_res['second_name'],
            '2'=>$comboname_res['thirdly_name'],
        ];


        $hardware_list_width = 5800;
        if($groupmindModel->combo_type == 0){
            $hardware_list_width = 5800;
        }else if($groupmindModel->combo_type == 1){
            $hardware_list_width = 2900;
        }else if($groupmindModel->combo_type == 2){
            $hardware_list_width = 1933;
        }

        foreach ($mind_data as $key => $value) {
            if (isset($mind_data[$key]['parentid']) && ($mind_data[$key]['parentid'] == 'sub2')) {
                $hardware_list[] = $value;
            }
        }

        //套餐价格
        $combo1_total_price = 0;
        $combo2_total_price = 0;
        $combo3_total_price = 0;
        foreach ($hardware_list as $key => $value) {
            if(isset($value['combo1']) && $value['combo1'] == 'true'){
                $hardware_list[$key]['combo1'] = '✔';
                $combo1_total_price += $value['price'];
            }else{
                $hardware_list[$key]['combo1'] = '';
            }
            if(isset($value['combo2']) && $hardware_list[$key]['combo2'] == 'true'){
                $hardware_list[$key]['combo2'] = '✔';
                $combo2_total_price += $value['price'];
            }else{
                $hardware_list[$key]['combo2'] = '';
            }
            if(isset($value['combo3']) && $hardware_list[$key]['combo3'] == 'true'){
                $hardware_list[$key]['combo3'] = '✔';
                $combo3_total_price += $value['price'];
            }else{
                $hardware_list[$key]['combo3'] = '';
            }
        }

        if(!empty($hardware_list)){
            $table_y->addRow(500);
            $table_y->addCell(12000, $cellColSpan)->addText('硬件设备', $fancyTableFontStyle,$fancyTableFontStyle);

            $table_y->addRow(500);
            $table_y->addCell(5700, $fancyTableCellStyle)->addText('品名/型号', $fancyTableFontStyle,$fancyTableFontStyle);
            $table_y->addCell(150, $fancyTableCellStyle)->addText('单位', $fancyTableFontStyle,$fancyTableFontStyle);
            $table_y->addCell(100, $fancyTableCellStyle)->addText('单价（元）', $fancyTableFontStyle,$fancyTableFontStyle);
            $table_y->addCell(100, $fancyTableCellStyle)->addText('数量', $fancyTableFontStyle,$fancyTableFontStyle);
            $table_y->addCell(150, $fancyTableCellStyle)->addText('金额（元）', $fancyTableFontStyle,$fancyTableFontStyle);



            for ($i = 0;$i<=$groupmindModel->combo_type;$i++){
                $table_y->addCell($hardware_list_width, $fancyTableCellStyle)->addText($comboname_array[$i], $fancyTableFontStyle,$fancyTableFontStyle);
            }

            $cellColSpan = array('valign' => 'center','gridSpan' => 8, 'valign' => 'center');

            foreach ($hardware_list as $key => $value){
                $table_y->addRow(500);
                $table_y->addCell(2800, $fancyTableCellStyle)->addText($value['only_topic'],$fancyTableCellStyle,$fancyTableCellStyle);
                $table_y->addCell(2200, $fancyTableCellStyle)->addText($value['hardware_unit'],$fancyTableCellStyle,$fancyTableCellStyle);
                $table_y->addCell(2200, $fancyTableCellStyle)->addText($value['hardware_price'],$fancyTableCellStyle,$fancyTableCellStyle);
                $table_y->addCell(2200, $fancyTableCellStyle)->addText($value['hardware_num'],$fancyTableCellStyle,$fancyTableCellStyle);
                $table_y->addCell(2200, $fancyTableCellStyle)->addText($value['price'],$fancyTableCellStyle,$fancyTableCellStyle);
                if($groupmindModel->combo_type == 0){
                    $table_y->addCell($hardware_list_width, $fancyTableCellStyle)->addText($value['combo1'],$fancyTableCellStyle,$fancyTableCellStyle);
                }else if($groupmindModel->combo_type == 1){
                    $table_y->addCell($hardware_list_width, $fancyTableCellStyle)->addText($value['combo1'],$fancyTableCellStyle,$fancyTableCellStyle);
                    $table_y->addCell($hardware_list_width, $fancyTableCellStyle)->addText($value['combo2'],$fancyTableCellStyle,$fancyTableCellStyle);
                }else if($groupmindModel->combo_type == 2){
                    $table_y->addCell($hardware_list_width, $fancyTableCellStyle)->addText($value['combo1'],$fancyTableCellStyle,$fancyTableCellStyle);
                    $table_y->addCell($hardware_list_width, $fancyTableCellStyle)->addText($value['combo2'],$fancyTableCellStyle,$fancyTableCellStyle);
                    $table_y->addCell($hardware_list_width, $fancyTableCellStyle)->addText($value['combo3'],$fancyTableCellStyle,$fancyTableCellStyle);
                }else{
                    $table_y->addCell(2000, $fancyTableCellStyle)->addText($value['combo1'],$fancyTableCellStyle,$fancyTableCellStyle);
                }
            }
        }

        //模块部分
        $fancyTableStyleName = 'price_table';
        $styleTable = array('borderSize' => 6, 'borderColor' => '999999');
        $fancyTableStyle = array('borderSize' => 6, 'borderColor' => '006699', 'cellMargin' => 80, 'alignment' => \PhpOffice\PhpWord\SimpleType\JcTable::CENTER);
        $fancyTableFirstRowStyle = array('borderBottomSize' => 18, 'borderBottomColor' => '0000FF', 'bgColor' => '66BBFF');
        $fancyTableCellBtlrStyle = array('valign' => 'center', 'textDirection' => \PhpOffice\PhpWord\Style\Cell::TEXT_DIR_BTLR);
        $fancyTableFontStyle = array('bold' => true,'align' => 'center','valign' => "center");

        $phpWord->addTableStyle($fancyTableStyleName, $styleTable);
        $section->addTextBreak(2);
        $table = $section->addTable($fancyTableStyleName);

        $cellColSpan_r = array('valign' => 'center','gridSpan' => 6, 'valign' => 'center');
        $table->addRow(500);
        $table->addCell(12000, $cellColSpan_r)->addText('功能模块', $fancyTableFontStyle,$fancyTableFontStyle);

        $table->addRow(500);
        $table->addCell(3000, $fancyTableCellStyle)->addText('模块',$fancyTableFontStyle,$fancyTableFontStyle);
        $table->addCell(3000, $fancyTableCellStyle)->addText('功能',$fancyTableFontStyle,$fancyTableFontStyle);
        $table->addCell(3000, $fancyTableCellStyle)->addText('金额',$fancyTableFontStyle,$fancyTableFontStyle);
        $model_list_width = 1000;
        if($groupmindModel->combo_type == 0){
            $model_list_width = 3000;
        }else if($groupmindModel->combo_type == 1){
            $model_list_width = 1500;
        }else if($groupmindModel->combo_type == 2){
            $model_list_width = 1000;
        }


        for ($i = 0;$i<=$groupmindModel->combo_type;$i++){
            $table->addCell($model_list_width, $fancyTableCellStyle)->addText($comboname_array[$i], $fancyTableFontStyle,$fancyTableFontStyle);
        }


        foreach ($model_list as $key => $value) {
            if(isset($value['combo1']) && $value['combo1'] == 'true'){
                $model_list[$key]['combo1'] = '✔';
                if(isset($value['editPrice']) && $value['editPrice'] == 'true'){
                    $combo1_total_price += $value['price'];
                }
            }else{
                $model_list[$key]['combo1'] = '';
            }

            if(isset($value['combo2']) && $value['combo2'] == 'true'){
                $model_list[$key]['combo2'] = '✔';
                if(isset($value['editPrice']) && $value['editPrice'] == 'true'){
                    $combo2_total_price += $value['price'];
                }
            }else{
                $model_list[$key]['combo2'] = '';
            }

            if(isset($value['combo3']) && $value['combo3'] == 'true'){
                $model_list[$key]['combo3'] = '✔';
                if(isset($value['editPrice']) && $value['editPrice'] == 'true'){
                    $combo3_total_price += $value['price'];
                }
            }else{
                $model_list[$key]['combo3'] = '';
            }

            foreach ($mind_data as $key1 => $value1) {
                if (isset($value1['parentid']) && $value1['parentid'] == $value['id']) {
                    $value1['modle'] = $value['topic'];

                    if(isset($value1['combo1']) && $value1['combo1'] == 'true'){
                        if(!isset($value['editPrice']) || $value['editPrice'] == 'false'){
                            $combo1_total_price += $value1['price'];
                        }
                        $value1['combo1'] = '✔';
                    }else{
                        $value1['combo1'] = '';
                    }

                    if(isset($value1['combo2']) && $value1['combo2'] == 'true'){
                        $value1['combo2'] = '✔';
                        if(!isset($value['editPrice'])|| $value['editPrice'] == 'false'){
                            $combo2_total_price += $value1['price'];
                        }
                    }else{
                        $value1['combo2'] = '';
                    }

                    if(isset($value1['combo3']) && $value1['combo3'] == 'true'){
                        $value1['combo3'] = '✔';
                        if(!isset($value['editPrice'])|| $value['editPrice'] == 'false'){
                            $combo3_total_price += $value1['price'];
                        }
                    }else{
                        $value1['combo3'] = '';
                    }
                    $list[] = $value1;

                    $model_list[$key]['child'][] = $value1;
                }
            }
        }

        $tableStyleCell = array('vMerge' => 'restart', 'valign' => "center",'align' => 'center');
        $tableStyleText = array('align' => 'center','valign' => "center");
        $tableStyleMergeRestart = array('vMerge' => 'restart', 'valign' => "center",'align' => 'center');
        $tableStyleMergeContinue = array('vMerge' => 'continue','valign' => "center",'align' => 'center');

        foreach ($model_list as $key => $value){
            $editPrice = false;
            if(isset($value['editPrice']) && $value['editPrice'] == 'true'){
                $editPrice = true;
            }
            $temp_velue = 0;
            if(!empty($value['child'])){
                foreach ($value['child'] as $key1 => $value1){
                    $table->addRow(500);
                    if($temp_velue === 0){
                        $table->addCell(3000,$tableStyleMergeRestart)->addText($value1['modle'],$tableStyleText,$tableStyleText);
                    }else if($temp_velue === 1){
                        $table->addCell(null,$tableStyleMergeContinue);
                    }
                    if(isset($value1['only_topic'])){
                        $table->addCell(3000,$tableStyleCell)->addText($value1['only_topic'],$tableStyleText,$tableStyleText);
                    }else{
                        $table->addCell(3000,$tableStyleCell)->addText($value1['topic'],$tableStyleText,$tableStyleText);
                    }

                    if($temp_velue === 0 && $editPrice === true){
                        $table->addCell(3000,$tableStyleMergeRestart)->addText($value['price'],$tableStyleText,$tableStyleText);

                        if($groupmindModel->combo_type == 0){
                            $table->addCell($model_list_width,$tableStyleMergeRestart)->addText($value['combo1'],$tableStyleText,$tableStyleText);
                        }else if($groupmindModel->combo_type == 1){
                            $table->addCell($model_list_width,$tableStyleMergeRestart)->addText($value['combo1'],$tableStyleText,$tableStyleText);
                            $table->addCell($model_list_width,$tableStyleMergeRestart)->addText($value['combo2'],$tableStyleText,$tableStyleText);
                        }else if($groupmindModel->combo_type == 2){
                            $table->addCell($model_list_width,$tableStyleMergeRestart)->addText($value['combo1'],$tableStyleText,$tableStyleText);
                            $table->addCell($model_list_width,$tableStyleMergeRestart)->addText($value['combo2'],$tableStyleText,$tableStyleText);
                            $table->addCell($model_list_width,$tableStyleMergeRestart)->addText($value['combo3'],$tableStyleText,$tableStyleText);
                        }else{
                            $table->addCell($model_list_width,$tableStyleMergeRestart)->addText($value['combo1'],$tableStyleText,$tableStyleText);
                        }

                    }else if($temp_velue === 1 && $editPrice === true){
                        $table->addCell(null,$tableStyleMergeContinue);

                        if($groupmindModel->combo_type == 0){
                            $table->addCell(null,$tableStyleMergeContinue);
                        }else if($groupmindModel->combo_type == 1){
                            $table->addCell(null,$tableStyleMergeContinue);
                            $table->addCell(null,$tableStyleMergeContinue);
                        }else if($groupmindModel->combo_type == 2){
                            $table->addCell(null,$tableStyleMergeContinue);
                            $table->addCell(null,$tableStyleMergeContinue);
                            $table->addCell(null,$tableStyleMergeContinue);
                        }else{
                            $table->addCell(null,$tableStyleMergeContinue);
                        }

                    }else{
                        if(!isset($value1['price'])){
                            $value1['price'] = 0.00;
                        }
                        $table->addCell(3000,$tableStyleCell)->addText($value1['price'],$tableStyleText,$tableStyleText);
                        if($groupmindModel->combo_type == 0){
                            $table->addCell($model_list_width,$tableStyleCell)->addText($value1['combo1'],$tableStyleText,$tableStyleText);
                        }else if($groupmindModel->combo_type == 1){
                            $table->addCell($model_list_width,$tableStyleCell)->addText($value1['combo1'],$tableStyleText,$tableStyleText);
                            $table->addCell($model_list_width,$tableStyleCell)->addText($value1['combo2'],$tableStyleText,$tableStyleText);
                        }else if($groupmindModel->combo_type == 2){
                            $table->addCell($model_list_width,$tableStyleCell)->addText($value1['combo1'],$tableStyleText,$tableStyleText);
                            $table->addCell($model_list_width,$tableStyleCell)->addText($value1['combo2'],$tableStyleText,$tableStyleText);
                            $table->addCell($model_list_width,$tableStyleCell)->addText($value1['combo3'],$tableStyleText,$tableStyleText);
                        }else{
                            $table->addCell($model_list_width,$tableStyleCell)->addText($value1['combo1'],$tableStyleText,$tableStyleText);
                        }

                    }
                    $temp_velue = 1;
                }
            }
        }

        $table->addRow(500);
        $table->addCell($model_list_width,array('valign' => 'center','gridSpan' => 2, 'valign' => 'center'))->addText("总计：",$tableStyleText,$tableStyleText);
        $table->addCell($model_list_width,$tableStyleCell)->addText($total_price,$tableStyleText,$tableStyleText);

        if($groupmindModel->combo_type == 0){
            $table->addCell(300,$tableStyleCell)->addText($combo1_total_price,$tableStyleText,$tableStyleText);
        }else if($groupmindModel->combo_type == 1){
            $table->addCell(300,$tableStyleCell)->addText($combo1_total_price,$tableStyleText,$tableStyleText);
            $table->addCell(300,$tableStyleCell)->addText($combo2_total_price,$tableStyleText,$tableStyleText);
        }else if($groupmindModel->combo_type == 2){
            $table->addCell(300,$tableStyleCell)->addText($combo1_total_price,$tableStyleText,$tableStyleText);
            $table->addCell(300,$tableStyleCell)->addText($combo2_total_price,$tableStyleText,$tableStyleText);
            $table->addCell(300,$tableStyleCell)->addText($combo3_total_price,$tableStyleText,$tableStyleText);
        }else{
            $table->addCell(300,$tableStyleCell)->addText($combo1_total_price,$tableStyleText,$tableStyleText);
        }

        $root_name = $groupmindModel->name.'报价单-'.date('Ymd');
        $file =$root_name.'.docx';
        if(ob_get_length()) ob_end_clean();
        header("Content-Description: File Transfer");
        header('Content-Disposition: attachment; filename="' . $file . '"');
        header('Content-Type: application/vnd.openxmlformats-officedocument.wordprocessingml.document');
        header('Content-Transfer-Encoding: binary');
        header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
        header('Expires: 0');
        ob_start(); //打开缓冲区
        $xmlWriter = \PhpOffice\PhpWord\IOFactory::createWriter($phpWord, 'Word2007');
        $xmlWriter->save("php://output",'Word2007',true);
    }


    public function simplephpword(){
        $id = input('param.id');
        $manage = isset($manage)?$manage : 0;
        if(isset($id) && !empty($id)){
            $groupmindModel = GroupmindModel::get($id);
            $mind_data = json_decode($groupmindModel->mind_json,true);
        }

        $phpWord = new \PhpOffice\PhpWord\PhpWord();


        $section = $phpWord->addSection(array('pageNumberingStart' => 1));

        // 页眉
        $header = $section->addHeader();
        //$header->addText('北京积木纵横网络科技有限公司');
        $header->addImage('static/admin/img/header.png', array('width' => 460, 'height' => 80, 'alignment' => \PhpOffice\PhpWord\SimpleType\Jc::CENTER));
        $section->addTextBreak(2);
        $phpWord->addTitleStyle(2, array('bold' => true, 'size' => 20, 'name' => 'Arial', 'Color' => '333'), array('align' => 'center'));
        $section->addTitle("公司报价单", 2);
        $section->addTextBreak(2);

        $tableStyle = array(
            'cellMargin' => 100,
            'alignment' => \PhpOffice\PhpWord\SimpleType\JcTable::CENTER,
            'borderSize' => 6,
        );
        $fancyTableFirstRowStyle = array('borderBottomSize' => 18, 'borderBottomColor' => 'ffffff', 'bgColor' => 'ffffff');

        $phpWord->addTableStyle('mytable', $tableStyle, $fancyTableFirstRowStyle);

        $table1 = $section->addTable('mytable');
        $cellRowSpan = array('vMerge' => 'restart', 'valign' => 'center','borderLeftSize'=>0, 'borderLeftColor'=>'ffffff','borderRightSize'=> 0,'borderRightColor'=>'ffffff',);
        $cellRowSpan_text = array('vMerge' => 'restart', 'valign' => 'center','borderLeftSize'=>0,'cellMarginLeft'=>5, 'borderLeftColor'=>'ffffff','borderRightSize'=> 0,'borderRightColor'=>'ffffff',);
        $cellHCentered = array('align' => 'left');
        $cellHCentered_text = array('align' => 'center'); //居中
        $table1->addRow(900);
        $table1->addCell(4500, $cellRowSpan)->addText('收件公司：',null, $cellHCentered_text); //设置该列可以跨行，且样式居中
        $table1->addCell(4500, $cellRowSpan_text)->addText($groupmindModel->company_addressee,null, $cellHCentered);
        $table1->addCell(4500, $cellRowSpan)->addText('发件人：',null, $cellHCentered_text);
        $table1->addCell(4500, $cellRowSpan_text)->addText($groupmindModel->sender,null, $cellHCentered);
        $table1->addRow(900);
        $table1->addCell(4500, $cellRowSpan)->addText('发件公司：',null, $cellHCentered_text);
        $table1->addCell(4500, $cellRowSpan_text)->addText($groupmindModel->company_sender,null, $cellHCentered);
        $table1->addCell(4500, $cellRowSpan)->addText('日期：',null, $cellHCentered_text);
        $table1->addCell(4500, $cellRowSpan_text)->addText(date('Y-m-d',strtotime($groupmindModel->date)),null, $cellHCentered);

        $table1->addRow(900);
        $table1->addCell(4500, $cellRowSpan)->addText('手机：',null, $cellHCentered_text);
        $table1->addCell(4500, $cellRowSpan)->addText($groupmindModel->mobile,null, $cellHCentered);
        $table1->addCell(4500, $cellRowSpan)->addText('地址：',null, $cellHCentered_text);
        $table1->addCell(4500, $cellRowSpan)->addText($groupmindModel->address,null, $cellHCentered);

        $table1->addRow(900);
        $table1->addCell(4500, $cellRowSpan)->addText('固定电话：',null, $cellHCentered_text);
        $table1->addCell(4500, $cellRowSpan)->addText($groupmindModel->tel,null, $cellHCentered);
        $table1->addCell(4500, $cellRowSpan)->addText('主题：',null, $cellHCentered_text);
        $table1->addCell(4500, $cellRowSpan)->addText($groupmindModel->subject,null, $cellHCentered);
        $section->addTextBreak(2);

        $section->addText('感谢您对本公司的信任和支持，您需要的报价如下:',array('bold' => true,'size' => 16));
        $section->addTextBreak(2);

        //功能模块
        $model_list = array();

        $list = array();
        foreach ($mind_data as $key => $value) {
            if($value['id'] == 'root'){
                $total_price = $value['price'];
                $root_name = $value['topic'];
            }

            if (isset($mind_data[$key]['parentid']) && ($mind_data[$key]['parentid'] == 'sub1')) {
                $is_h = strpos($value['topic'],"/");
                if($is_h){
                    $value['topic'] = substr($value['topic'],0,$is_h);
                }
                $model_list[] = $value;
            }
        }


        //dump($mind_data);

        $fancyTableStyleName = 'price_table';
        $fancyTableStyle = array('borderSize' => 6, 'borderColor' => '003322', 'cellMargin' => 80, 'alignment' => \PhpOffice\PhpWord\SimpleType\JcTable::CENTER);
        $fancyTableFirstRowStyle = array('borderBottomSize' => 18, 'borderBottomColor' => '0000FF', 'bgColor' => '#003322');
        $fancyTableCellStyle = array('valign' => 'center','align' => 'center',);
        $fancyTableCellBtlrStyle = array('valign' => 'center', 'textDirection' => \PhpOffice\PhpWord\Style\Cell::TEXT_DIR_BTLR);
        $fancyTableFontStyle = array('bold' => true,'valign' => 'center','align' => 'center');
        $styleTable = array('borderSize' => 6, 'borderColor' => '999999');
        $phpWord->addTableStyle($fancyTableStyleName, $styleTable);
        $table_y = $section->addTable($fancyTableStyleName);

        $cellColSpan = array('valign' => 'center','gridSpan' => 8, 'valign' => 'center');

        //模块部分
        $fancyTableStyleName = 'price_table';
        $styleTable = array('borderSize' => 6, 'borderColor' => '999999');
        $fancyTableStyle = array('borderSize' => 6, 'borderColor' => '006699', 'cellMargin' => 80, 'alignment' => \PhpOffice\PhpWord\SimpleType\JcTable::CENTER);
        $fancyTableFirstRowStyle = array('borderBottomSize' => 18, 'borderBottomColor' => '0000FF', 'bgColor' => '66BBFF');
        $fancyTableCellBtlrStyle = array('valign' => 'center', 'textDirection' => \PhpOffice\PhpWord\Style\Cell::TEXT_DIR_BTLR);
        $fancyTableFontStyle = array('bold' => true,'align' => 'center','valign' => "center");

        //$phpWord->addTableStyle($fancyTableStyleName, $fancyTableStyle, $fancyTableFirstRowStyle);
        $phpWord->addTableStyle($fancyTableStyleName, $styleTable);
        $section->addTextBreak(2);
        $table = $section->addTable($fancyTableStyleName);

        $cellColSpan_r = array('valign' => 'center','gridSpan' => 6, 'valign' => 'center');
        $table->addRow(500);
        $table->addCell(12000, $cellColSpan_r)->addText('功能模块', $fancyTableFontStyle,$fancyTableFontStyle);

        $table->addRow(500);
        $table->addCell(6000, $fancyTableCellStyle)->addText('模块',$fancyTableFontStyle,$fancyTableFontStyle);
        $table->addCell(6000, $fancyTableCellStyle)->addText('功能',$fancyTableFontStyle,$fancyTableFontStyle);


        foreach ($model_list as $key => $value) {
            foreach ($mind_data as $key1 => $value1) {
                if (isset($value1['parentid']) && $value1['parentid'] == $value['id']) {
                    $is_h = strpos($value1['topic'],"/");
                    if($is_h){
                        $value1['modle'] = substr($value1['topic'],0,$is_h);
                        $value1['topic'] = substr($value1['topic'],0,$is_h);
                    }else{
                        $value1['modle'] = $value['topic'];
                    }
                    //$list[] = $value1;
                    $model_list[$key]['child'][] = $value1;
                }
            }
        }
//dump($model_list);exit;
        //dump($combo1_total_price);exit;
        $tableStyleCell = array('vMerge' => 'restart', 'valign' => "center",'align' => 'center');
        $tableStyleText = array('align' => 'center','valign' => "center");
        $tableStyleMergeRestart = array('vMerge' => 'restart', 'valign' => "center",'align' => 'center');
        $tableStyleMergeContinue = array('vMerge' => 'continue','valign' => "center",'align' => 'center');
        $cellColSpan = array('gridSpan' => 2, 'valign' => 'center','vMerge' => 'restart', 'valign' => "center",'align' => 'center');
        //$cellColSpan = array('gridSpan' => 2, 'valign' => 'center');
        foreach ($model_list as $key => $value){

            $temp_velue = 0;
            if(!empty($value['child'])){
                foreach ($value['child'] as $key1 => $value1){
                    $table->addRow(500);
                    if($temp_velue === 0){
                        $table->addCell(6000,$tableStyleMergeRestart)->addText($value1['modle'],$tableStyleText,$tableStyleText);
                    }else if($temp_velue === 1){
                        $table->addCell(null,$tableStyleMergeContinue);
                    }
                    $table->addCell(6000,$tableStyleCell)->addText($value1['topic'],$tableStyleText,$tableStyleText);
                    $temp_velue = 1;
                }
            }else{
                /*$table->addRow(500);
                $table->addCell(12000,$cellColSpan)->addText($value['topic'],$tableStyleText,$tableStyleText);*/
                $table->addRow(500);
                $table->addCell(6000,$tableStyleCell)->addText($value['topic'],$tableStyleText,$tableStyleText);
                $table->addCell(6000,$tableStyleCell)->addText(null,$tableStyleText,$tableStyleText);
            }
        }

        //dump($model_list);exit;

        $root_name = $groupmindModel->name.'功能-'.date('Ymd');
        $file =$root_name.'.docx';
        if(ob_get_length()) ob_end_clean();
        header("Content-Description: File Transfer");
        header('Content-Disposition: attachment; filename="' . $file . '"');
        header('Content-Type: application/vnd.openxmlformats-officedocument.wordprocessingml.document');
        header('Content-Transfer-Encoding: binary');
        header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
        header('Expires: 0');
        ob_start(); //打开缓冲区
        $xmlWriter = \PhpOffice\PhpWord\IOFactory::createWriter($phpWord, 'Word2007');
        $xmlWriter->save("php://output",'Word2007',true);
    }

}